package com.hrm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hrm.dao.MenuMapper;
import com.hrm.dao.RewardMapper;
import com.hrm.dao.RoleMapper;
import com.hrm.dao.UserMapper;
import com.hrm.entity.Menu;
import com.hrm.entity.Reward;
import com.hrm.entity.User;
import com.hrm.util.Page;

public class Test {

	public static void main(String[] args) {
		 //读取spring配置文件
        BeanFactory beanFactory = new ClassPathXmlApplicationContext(
                "spring.xml");
        //通过spring配置文件生成的beanFactory获得SqlSessionFactory
        SqlSessionFactory factory = (SqlSessionFactory) beanFactory
                .getBean("sqlSessionFactory");
        //获得SqlSession
        SqlSession session = factory.openSession();
        //用session根据Mapper获得对象的Mapper对象
        UserMapper userMapper = session.getMapper(UserMapper.class);
        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
        MenuMapper menuMapper = session.getMapper(MenuMapper.class);
        RewardMapper rewardMapper = session.getMapper(RewardMapper.class);
        
        User user = new User();
        //数据插入
        //System.out.println(userMapper.insertUser(user));
        //userMapper.insertUser(user);
        //数据更新
//        user.setId(2);
//        user.setUserName("Test");
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("name", "mapname");
//        map.put("id", 2);
//        userMapper.updateUserByMap(map);
//        
//        //数据删除
//        userMapper.deleteUserById(1);
//        user.setId(2);
//        map.remove("id");
//        userMapper.deleteUserByMap(map);
//        //数据查询
//        user.setId(0);
//        user.setUserName("spring");
//        List<User> users = userMapper.selectAllUser();
//        for (User u : users) {
//            System.out.println(u.getUserName());
//        }
//        System.out.println(userMapper.selectAllUser());
//        System.out.println(userMapper.selectUserById(4));
//        User user2 = new User();
//        user2.setUserName("admin");
//        user2.setPassword("admin");
//        System.out.println(userMapper.selectUser(user));
//        Map<String,Object> map =new HashMap<String, Object>();
//        map.put("sql", "order by create_date");
//        //map.put("password", "admin");
//        System.out.println(userMapper.selectUserByMap(map).get(0));
//       // Page page = new Page();
       // page.setCounts(30);
        //System.out.println(page);
        //System.out.println(userMapper.selectUserById(5));
       // System.out.println(roleMapper.selectRoleById(4));
//        Menu menu = new Menu();
//        menu.setId(40);
//        System.out.println(menuMapper.selectMenu(menu));
        Reward reward = new Reward();
        reward.setId(1);
        System.out.println(rewardMapper.selectReward(reward));
	}

}
